//
//  PaddingLabel.swift
//  ExtremeHealth
//
//  Created by Zhongkai Li 李忠凯 on 2018/9/29.
//  Copyright © 2018 GanDongKeJi. All rights reserved.
//

class PaddingLabel: UILabel {

    private var topInset: CGFloat = 5.0
    private var bottomInset: CGFloat = 5.0
    private var leftInset: CGFloat = 7.0
    private var rightInset: CGFloat = 7.0

    var insets: UIEdgeInsets {
        set {
            topInset = newValue.top
            bottomInset = newValue.bottom
            leftInset = newValue.left
            rightInset = newValue.right
        }
        get {
            return UIEdgeInsets(top: topInset, left: leftInset, bottom: bottomInset, right: rightInset)
        }
    }

    override func drawText(in rect: CGRect) {
        super.drawText(in: UIEdgeInsetsInsetRect(rect, insets))
    }

    override var intrinsicContentSize: CGSize {
        let size = super.intrinsicContentSize
        return CGSize(width: size.width + leftInset + rightInset,
                      height: size.height + topInset + bottomInset)
    }
}
